package com.mifan.service.impl;


import com.mifan.entity.Resources;
import com.mifan.mapper.ResourceMapper;
import com.mifan.service.IResourceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 资源表 服务实现类
 * </p>
 *
 * @author Milan
 * @since 2024-09-13
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resources> implements IResourceService {

    @Resource
    private ResourceMapper resourceMapper;

//    @Override
//    public PageInfo<Resources> selectAll(Integer pageNum, Integer pageSize) {
//        PageHelper.startPage(pageNum, pageSize);
//        List<Resources> resources = resourceMapper.selectList(null);
//        PageInfo page = new PageInfo(resources);
//        return page;
//    }

    @Override
    public List<String> getResourcesByUserUsername(String username) {
        List<Resources> resourcesList = resourceMapper.getResourcesByUserUsername(username);
        List<String> resources = new ArrayList<>();
        for (Resources res : resourcesList) {
            resources.add(res.getCode());
        }
        System.out.println("当前用户权限: " + resources);
        return resources;
    }
}
